package com.pan.behavioral.template.read.impl;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class ReadChineseTxt extends BasicReadFile{


    private BufferedReader reader;

    public ReadChineseTxt(String path) {
        super(path);
    }

    @Override
    public void openFile() {
        super.openFile();
        InputStreamReader inputStreamReader = new InputStreamReader(super.inputStream);
        reader = new BufferedReader(inputStreamReader);
    }

    @Override
    public void end() {
        try {
            reader.close();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
        super.end();
    }

    @Override
    public boolean hasNext() {
        try {
            return reader.ready();
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }

    @Override
    public String read() {
        try {
            return reader.readLine() + "\n";
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
